﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL.Admin;
using DBUtility;
using System.Data.SqlClient;

public partial class Admin_FunctionManageMent : System.Web.UI.Page
{
    private void bindGrid()
    {
        //给存储过程传参数
        info.TableName = "FunctionNew";
        info.PageSize = AspNetPager1.PageSize;
        info.PageIndex = AspNetPager1.CurrentPageIndex;
        info.KeyField = "FID";
        info.FieldType = "int";
        info.SqlFile = "*";
        info.SqlOrder = "order by FID";
        info.SqlWhere = "where ALID=" + Convert.ToInt32(ddlGL.SelectedItem.Value.ToString().Trim());
        AspNetPager1.RecordCount = Pager.GetRecordCount(info);
        GVAdminFumction.DataSource = Pager.GetListForDataSet(info);
        GVAdminFumction.DataBind(); 
    }
    private AspNetPagerInfo info = new AspNetPagerInfo();
    private AspNetPager Pager = new AspNetPager();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["admin"].ToString().Trim() != "1")
            {
                Response.Redirect("Login.aspx");
            }
            if (!IsPostBack)
            {
                ddlGL.DataSource = AdminServices.SP_select("AdminLevel", "ALID,ALNAame");
                ddlGL.DataTextField = "ALNAame";
                ddlGL.DataValueField = "ALID";
                ddlGL.DataBind();
                bindGrid();
            }
        }
        catch (Exception )
        {

        }
    }

    //查询功能
    protected void ddlGL_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            bindGrid();
        }
        catch (Exception ex)
        {
            lblMessages.Visible = true;
            lblMessages.Text = "发生异常：" + ex.Message.ToString().Trim();
        }
    }

    //添加新功能
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("addFunction.aspx?ALID=" + ddlGL.SelectedItem.Value.ToString().Trim());
    }
    //分页控件的刷新方法
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bindGrid();
    }
    //删除
    protected void GVAdmin_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            SqlParameter[] parms = new SqlParameter[]
           {
               new SqlParameter ("@ALID",SqlDbType .Int),
               new SqlParameter ("@AFID",SqlDbType .Int)
           };
            parms[0].Value = Convert.ToInt32(ddlGL.SelectedItem.Value.ToString().Trim());
            parms[1].Value = Convert.ToInt32(GVAdminFumction.Rows[e.RowIndex].Cells[0].Text.ToString().Trim());
            if (SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocal, CommandType.StoredProcedure, "S_deleteOneFunctionByALIDandAFID", parms) > 0)
            {
                lblMessages.Visible = true;
                lblMessages.Text = "删除成功";
                ddlGL_SelectedIndexChanged(sender, null);
            }
            else
            {
                lblMessages.Visible = true;
                lblMessages.Text = "删除失败";
            }
        }
        catch (Exception ex)
        {
            lblMessages.Visible = true;
            lblMessages.Text = "发生异常：" + ex.Message.ToString().Trim();
        }
    }
   
}
